package com.mokairui.basic.demo4;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author Mokairui
 * @Description 开发实现伪异步通信架构
 * @Since 2021/6/28
 */
public class Server {
    public static void main(String[] args) {
        try {
            // 1.注册端口
            ServerSocket serverSocket = new ServerSocket(9999);
            // 2.定义一个循环接受客户端的Socket连接请求
            // 初始化一个线程池对象
            HandlerSocketServerPool pool = new HandlerSocketServerPool(8, 10);
            while (true) {
                Socket socket = serverSocket.accept();
                // 3.把socket对象交割一个线程池进行处理
                // 把socket封装成一个任务对象交给线程池处理
                Runnable target = new ServerRunnableTarget(socket);
                pool.execute(target);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
